define(["app", 
        "md5","ecb",
        "resources/UserResource", 
        "services/MenuService",
        "services/UserService",
        "services/NotificationService"
], function(app) {
	
	var deps = ["$scope", "UserResource", "$location", "UserService","$stateParams","MenuService","NotificationService"];
	
	function controller($scope, UserResource, $location, UserService,$stateParams,MenuService,NotificationService) {
		$scope.accessToken = $stateParams.accessToken;
        debugger;
		

            //NotificationService.requestPermission();
			UserResource.accessTokenLogin({
				accessToken : $scope.accessToken		
			}, function(user) {
				if(user.authenticated) {
					UserService.setCurrentUser(user);
					UserService.setLastLoginUser(user.loginName);
					//菜单
					$scope.menuConfig = MenuService.config;
					$location.path($scope.menuConfig.news.locationURL);
				} else {
					$scope.errorMessage = user.errorMessage;
					$scope.loginVo.needLoginCode = user.needLoginCode;
					UserService.removeCurrentUser();	
					$location.path("/login");
				}
			});
		};

 


	
	controller.$inject = deps;
	app.lazy.controller("AccessTokenLoginController", controller);
});
